package com.kuangstudy.common.date;

import java.util.Calendar;
import java.util.Date;

/**
 * ClassName: Demo2
 * date: 2021/07/14 18:57:28
 *
 * @author zlk
 */
public class Demo2 {
    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar.getTime().toLocaleString());
        System.out.println(calendar.getTimeInMillis());
        /*获取时间信息*/
        /*获取年*/
        int year = calendar.get(Calendar.YEAR);
        /*获取月*/
        int month = calendar.get(Calendar.MONDAY);
        /*获取日*/
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        /*获取小时*/
        int hour = calendar.get(Calendar.HOUR_OF_DAY);//HOUR_OF_DAY 24小时 HOUR 12小时
        /*获取分钟*/
        int minute = calendar.get(Calendar.MINUTE);
        /*获取秒*/
        int second = calendar.get(Calendar.SECOND);
        /*月份加1表示正常*/
        System.out.println(year+"-"+(month+1)+"-"+day+" "+hour+":"+minute+":"+second);
        /*修改时间为昨天*/
        calendar.set(Calendar.DAY_OF_MONTH,13);
        System.out.println(calendar.getTime().toLocaleString());//2021-7-13 19:09:06
        /*add方法修改时间*/
        calendar.add(Calendar.HOUR_OF_DAY,1);
        System.out.println(calendar.getTime().toLocaleString());//2021-7-13 20:09:06
        calendar.add(Calendar.HOUR_OF_DAY,-1);
        System.out.println(calendar.getTime().toLocaleString());//2021-7-13 19:09:06

        /*补充方法*/
        int maximum = calendar.getMaximum(Calendar.DAY_OF_MONTH);
        int minimum = calendar.getMinimum(Calendar.DAY_OF_MONTH);
        System.out.println(maximum);//31
        System.out.println(minimum);//1


    }
}
